package 实践.class_07.Demo_02;

class GeometricObject {
    //颜色
    private String color;
    //是否填充
    private boolean filled;
    //构造方法
    public GeometricObject() {
        this.color = "white";
        this.filled = false;
    }

    public GeometricObject(String color, boolean filled) {
        this.color = color;
        this.filled = filled;
    }

    /**
     * 获取
     * @return color
     */
    public String getColor() {
        return color;
    }

    /**
     * 设置
     * @param color
     */
    public void setColor(String color) {
        this.color = color;
    }

    /**
     * 获取
     * @return filled
     */
    public boolean isFilled() {
        return filled;
    }

    /**
     * 设置
     * @param filled
     */
    public void setFilled(boolean filled) {
        this.filled = filled;
    }
    @Override
    public String toString() {
        return "GeometricObject{color = " + color + ", filled = " + filled + "}";
    }
}
class Triangle extends GeometricObject {
    //三角形的三条边
    private double side1;
    private double side2;
    private double side3;

    public Triangle() {
        this.side1 = 1.0;
        this.side2 = 1.0;
        this.side3 = 1.0;
    }

    public Triangle(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public Triangle(double side1, double side2, double side3, String color, boolean filled) {
        super(color, filled);
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }
    //getter和setter方法
    public double getSide1() {
        return side1;
    }

    public void setSide1(double side1) {
        this.side1 = side1;
    }

    public double getSide2() {
        return side2;
    }

    public void setSide2(double side2) {
        this.side2 = side2;
    }

    public double getSide3() {
        return side3;
    }

    public void setSide3(double side3) {
        this.side3 = side3;
    }
    //计算三角形的周长
    public double getPerimeter() {
        return side1 + side2 + side3;
    }
    //计算三角形的面积
    public double getArea() {
        double s = getPerimeter() / 2;
        return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
    }
    public String toString() {
        return "Triangle{side1 = " + side1 + ", side2 = " + side2 + ", side3 = " + side3 + ", color = " + getColor() + ", filled = " + isFilled() + "}";
    }
}
